package com.mypaper.dag;
public class Benchmarks {
	/*
	 * 根据给定的DAG图，给计算矩阵及通信矩阵赋值
	 */
	
	public int TASKNUM;
    public int PROCNUM;//3,4,5,6,7;
	public float[][] comm;
	public float[][] comp;
	public int[][] commDAG;
	private float comp_base=64;
	private float CCR = (float) 1.0;
	private float BEITA = 0.5f;//处理器异构因子（0.1,0.25,0.5，0.75,1,1.25,1.5）这里设置不能大于1.5；
    
    public Benchmarks(short TASKNUM, short PROCNUM, int[][] commDAG, float CCR){
    	this.TASKNUM=TASKNUM;
    	this.PROCNUM=PROCNUM;
    	this.commDAG=commDAG; 
    	this.comm=new float[TASKNUM][TASKNUM];
    	this.comp=new float[TASKNUM][PROCNUM]; 
    	this.CCR=CCR;
    	
    	setComm();
    	setComp();
    }
    
   public void setComm(){
	   float comm_base=comp_base*CCR;
	   for(int i=0; i<TASKNUM; i++)
		   for(int j=0; j<TASKNUM; j++)
			   if(commDAG[i][j]!=0)
				   comm[i][j]=(int)((Math.random()+0.5)*comm_base/2) + comm_base/2;//产生通信代价
			   else
				   comm[i][j]=0;
   }
   
	public void setComp(){
		if(BEITA < -1.5 || BEITA > 1.5)
		{
			
			try
			{
				throw new Exception();
			} catch (Exception e)
			{
				System.out.println("处理器异构因子设置有误！");
				e.printStackTrace();
				System.exit(0);
			}
		}
		for(int i = 0; i < TASKNUM; i++)
		{
			for(int j = 0; j < PROCNUM; j++)
			{
				comp[i][j] = (int)(((Math.random()-0.5)*BEITA + 1)*comp_base);
			}
		}
//		for(int i=0; i<TASKNUM; i++)
//			for(int j=0; j<PROCNUM; j++)
//				comp[i][j]=(int)(Math.random()*comp_base/2)+comp_base/5;//产生计算代价
	}
	
	public void print(){
		for(int i=0; i<TASKNUM; i++){
			for(int j=0; j<TASKNUM; j++)
				System.out.print(comm[i][j]+"\t");
			System.out.println();
		}
		System.out.println();
		for(int i=0; i<TASKNUM; i++){
			for(int j=0; j<PROCNUM; j++)
				System.out.print(comp[i][j]+"\t");
			System.out.println();
		}
		System.out.println();
	}	
}
